﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using DBWorker;
using System.Data.SqlClient;

namespace DBWorkerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Путь к файлу базы
            // База данных ОТЛ-Хлеб
            /*
            string dbPath = @"D:\code\c_sharp_hleb\_db\11.03.31\transport.mdf";
            DBWorkerMSSQL worker = new DBWorkerMSSQL( dbPath );

            // Получим таблицу всех точек
            Console.WriteLine("Загрузка данных о клиентах из базы mssql...");
            DataTable tableKlients = worker.GetDataTableByTableName("klients");
            for (int i = 0; i < tableKlients.Rows.Count; i++)
            {
                Console.WriteLine("{0}:{1}", i, tableKlients.Rows[i]["kratName"]);
            }

            // Получим список Депо
            Console.WriteLine("\n\nЗагрузка данных депо из базы mssql...");
            DataTable tableShed = worker.GetDataTableByCommand("SELECT * FROM klients WHERE kod > 99999990");
            for (int i = 0; i < tableShed.Rows.Count; i++)
            {
                Console.WriteLine("№{0}: {1} {2}", i, tableShed.Rows[i]["kratName"], tableShed.Rows[i]["address"]);
            }
            Console.ReadKey();
             */

            /*
            DBWorkerMySQL worker = new DBWorkerMySQL();
            // Server=mysql01-4-utf8.corp.parking.ru;Port=3306;Uid=pritchin_4;Pwd=2Zotjo07bD;database=[pritchin_4]            
            worker.Server = "mysql01-4-utf8.corp.parking.ru";
            worker.UserID = "pritchin_4";
            worker.Password = "2Zotjo07bD";
            worker.DatabaseName = "[pritchin_4]";
            worker.Port = "3306"; 
             */ 
             
            /*
            worker.Server = "localhost";
            worker.UserID = "root";
            worker.Password = "";
            worker.DatabaseName = "dbase";
            worker.Port = "3306";
             */

            /*
            DBWorkerMSSQL worker = new DBWorkerMSSQL();
            worker.Type = MSSQLType.RemoteSQLAuth;
            worker.DataSource = "pritchin_5.hosting.parking.ru";
            worker.DatabaseName = "pritchin_5";
            worker.UserID = "pritchin_5";
            worker.Password = "M^6SyxpHUw";
 
            try
            {
                //worker.ExecuteScalar("INSERT INTO analisys (date, query) VALUES ('2011-12-10', 'купить плитку недорого')");
                string connstr = worker.GetConnectionString();
                DataTable table = worker.GetDataTableByCommand("SELECT * FROM search");
                for (int i = 0; i < table.Rows.Count; i++ )
                    Console.WriteLine("{0} {1}", table.Rows[i]["url"], table.Rows[i]["searcher"]);
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }*/

            // Инициализация для работы с БД
            DBWorkerMSSQL worker = new DBWorkerMSSQL();
            worker.Type = MSSQLType.RemoteWinAuth;
            worker.DataSource = "PAUL-ПК";
            worker.Server = "PAUL-ПК";
            worker.UserID = "paul-ПК\\paul";
            worker.Password = "";
            worker.DatabaseName = "Course";
            worker.Port = "3306";
            SqlCommand comm = new SqlCommand(@"
                                INSERT INTO FoodItem 
                                    (CategoryId, FoodItemTypeId, Name, Code) 
                                    VALUES (350, 1, 'ffff', '1.1.1')
                                ");
            object obj = worker.ExecuteScalarLastIdentity(comm);
            int? id = Convert.ToInt32( obj );
        }
    }
}
